//
//  HomePageCollectionViewCell.m
//  B_WatchHome
//
//  Created by dllo on 15/12/22.
//  Copyright © 2015年 DHF. All rights reserved.
//

#import "HomePageCollectionViewCell.h"
#import <UIImageView+WebCache.h>
#import <Masonry.h>

@implementation HomePageCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubViews];
    }
    
    return self;
}

- (void)createSubViews
{
    if (![self.model.author isEqualToString:@""]) {
        //图片
        self.headImageView = [[UIImageView alloc] init];
        [self.contentView addSubview:self.headImageView];
        
        [self.headImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.and.right.mas_equalTo(0);
            make.top.mas_equalTo(20);
            make.bottom.mas_equalTo(-160);
        }];
        
        
        //日期
        self.dateLabel = [[UILabel alloc] init];
        self.dateLabel.font = [UIFont boldSystemFontOfSize:12];
        [self.contentView addSubview:self.dateLabel];
        [self.dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.headImageView.mas_bottom).offset(10);
            make.left.mas_equalTo(10);
        }];
        
        
        //第一行文字
        self.titleLabel = [[UILabel alloc] init];
        self.titleLabel.font = [UIFont boldSystemFontOfSize:15];
        self.titleLabel.numberOfLines = 2;
        [self.contentView addSubview:self.titleLabel];
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(20);
            make.right.mas_equalTo(0);
            make.top.equalTo(self.dateLabel).offset(20);
        }];
      
        //第二行文字
        self.contentLabel = [[UILabel alloc] init];
        self.contentLabel.backgroundColor = [UIColor clearColor];
        self.contentLabel.font = [UIFont boldSystemFontOfSize:13];
        self.contentLabel.numberOfLines = 0;
        [self.contentView addSubview:self.contentLabel];
        [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(20);
            make.right.mas_equalTo(-5);
            make.top.equalTo(self.titleLabel.mas_bottom).offset(10);
        }];
        
        
        
        
        
        
    }
}




- (void)setModel:(HomePageModel *)model
{
    if (_model != model) {
        _model = model;
    }
    
    NSURL *url = [NSURL URLWithString:self.model.cover_landscape];
    
    [self.headImageView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@""]];
    
    NSString *str =self.model.pubdate;
    
    self.dateLabel.text = str;
    
    self.titleLabel.text = self.model.title;
    
    self.contentLabel.text = self.model.summary;
    

    
    
}

@end
